#pragma once

#include<string>

namespace PCmode
{
    template<class T>
    class Task
    {
    public:
        Task(T x = 0, T y = 0, char op = '+')
            :_x(x), _y(y), _op(op), _res(0), _err(0)
        {}

        void operator()()
        {
            switch(_op)
            {
                case '+':
                    _res=_x+_y;
                break;
                case '-':
                    _res=_x-_y;
                break;
                case '*':
                    _res=_x*_y;
                break;
                case '/':
                if(_y==0)
                        _err=-1;
                    else
                        _res=_x/_y;
                break;
                case '%':
                    if(_y==0)
                        _err=-2;
                    else
                        _res=_x%_y;
                break;
                default:
                    _err=-3;
                break;
            }
        }

        std::string getResult()
        {
            std::string ret=std::to_string(_x)+" "+_op+" "+std::to_string(_y);
        
            if(_err)
            {
                ret+=" errpr";

                if(_err==-1)
                    ret+=" [-1] \t /0 引发错误";
                else if(_err==-2)
                    ret+=" [-2] \t %0 引发错误";
                else
                    ret+=" [-3] \t 出现了除[+-*/%]以外的非法操作符";
            }
            else{
                ret+="="+std::to_string(_res);
            }
            return ret;
        }

    private:
        T _x;
        T _y;
        char _op;
        T _res;
        int _err;
    };
}